package cn.kgc.ubagnet.controller;

import cn.kgc.ubagnet.pojo.Protype;
import cn.kgc.ubagnet.service.protype.ProtypeService;
import cn.kgc.ubagnet.utils.ResultEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class controller {

    @Resource
    ProtypeService protypeService;

    @RequestMapping("/seleProtype")
    public Map<String,Object> seleProtype(@RequestParam(value = "level",required = false,defaultValue = "0")Integer level,
                                                   @RequestParam(value = "parentid",required = false,defaultValue = "0")Integer parentid,
                                                   @RequestParam(value = "level2",required = false,defaultValue = "1")Integer level2){
        List<Protype> protypes = protypeService.selePro(level, parentid);
        Map<String,Object> map=new HashMap<>();
        //查询一级菜单
        List<Protype> protypes1 = protypeService.selePro(1, 0);
//        查询二级分类
        List<Protype> protypes2 = protypeService.selePro(2, level2);
        Map<Object,Object> map1=new HashMap<>();
        List<Object> list2=new ArrayList<>();
        for (Protype protype : protypes2) {
            List<Object> list=new ArrayList<>();
            List<Protype> protypes3 = protypeService.selePro(3, protype.getId());
            for (Protype protype1 : protypes3) {
                list.add(protype1.getProname());
                map1.put(protype.getProname(),list);
            }
            list2.add(map1);
        }
        List<Object> listmap=new ArrayList<>();
        for (int i=0;i<list2.size();i++) {
            listmap.add(list2.get(i));
            break;
        }
        //查询三级分类
        map.put("level1",protypes1);
        map.put("level2",protypes2);
        map.put("level3",listmap);
        return map;
    }


}
